<template>
  <div>
    <component-head></component-head>
    <div class="content">
      <!-- 坐标分类列表 -->
      <div class="left">
        <ul>
          <li 
            v-for="item in items"
            :key="item.id"
            @click="choseCate(item.id)">
              {{item.name}}
            </li>
        </ul>
      </div>
      <!-- 右边显示商品列表 -->
      <div class="right">
          <div @click="enterdetail(catelistitem.id)" class="rocomd-min" 
            v-for="catelistitem in catelist"
            :key='catelistitem.id'
          >
            <img :src="catelistitem.pic" alt="">
            <p>{{ catelistitem.name }}</p>
        </div>
      </div>
    </div>
    
    <mybarba></mybarba>
  </div>
</template>

<script>
import componentHead from '@/views/home/components/ComponentHead'
import mybarba from '@/components/mybarba'
// import recommod from '@/views/Itemlist/component/ListRecommod'
import { fetchcate, fetchitems, fetchdetail } from '@/api/request'
export default {
  components: {
    componentHead,
    mybarba
  },
  data () {
    return {
      // 存储分类参数
      items: [],
      // 存储分类列表参数
      catelist: []
    }
  },
  created () {
    this.fetchcate()
    // 进入分类页面显示第一个分类的列表
    this.choseCate (173959)
  },
  methods: {
    // 点击商品进入详情页
    enterdetail (id) {
      this.$router.push(`/detail/${id}`)
    },
    // 获取分类参数
    fetchcate () {
      fetchcate().then(res => {
        if(res.data.code ===0){
          this.items = res.data.data
        }
      })
    },
    // 点击获取分类下商品
    choseCate (id) {
      console.log(id);
      fetchitems({
        categoryId:id
      }).then(res => {
        console.log(res)
        if(res.data.code === 0){
          this.catelist = res.data.data
        }
      })

    }
  }
}
</script>

<style lang="scss" scoped>
.content{
  position: fixed;
  left: 0;
  right: 0;
  top: 46px;
  bottom: 50px;
  display: flex;
  .left{
    display: flex;
    flex: 3;
    // background: rgb(54, 186, 219);
    height: 100%;
    ul{
      width: 100%;
      border-right: 1px solid black;
      li{
        height: 35px;
        line-height: 35px;
        font-size: 16px;
        background: white;
        width: 100%;
        margin: 5px auto;
        text-align: center;
      }
    }
  }
  .right{
    font-size: 16px;
    display: flex;
    flex-wrap: wrap;
    align-content: flex-start;
    flex: 7;
    height: 100%;
    .rocomd-min{
      width: 100px;
      height: 100px;
      margin: 10px;
    }
    img{
      width: 100px;
      height: 80px;
    }
    p{
      font-size: 10px;
    }
    // background: rgb(59, 125, 224);
  }
}
  
</style>
